<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Info extends Model
{
    protected $guarded = [];
    //


    public function sendMail($sender, $receiver, $content)
    {
        return $this->create([
            'senderid'=>$sender,
            'receiverid'=>$receiver,
            'content' => $content
        ]);
    }

    public function sender()
    {
        return $this->belongsTo('App\User','senderid');
    }

    public function receiver()
    {
        return $this->belongsTo('App\User','receiverid');
    }

    public function scopeRecent($query)
    {
        return $query->orderBy('created_at','desc');
    }
}
